


<head>
<script type="text/javascript">
function show_alert()
{
alert("Comment field cannot be left blank or only contain white space.");
}
</script>
</head>
<?php
//Create a variable called $con and set it to the connection command and its respected data below
$con = mysql_connect("fdb3.awardspace.com","891782_chris","design3");

//If the connection fails, then report error
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

//Command to select database. 
mysql_select_db("891782_chris") or die(mysql_error());

//Create a new variable called $sql and set it to the incoming comment from user
$time = date("d/m/y : H:i:s", time());
$sql="INSERT INTO Test (Comment,Date)VALUES('$_POST[comments]','$time')";
$comm = $_POST['comments'];


if(!empty($comm) && strlen(trim($comm)) > 0 )
{
mysql_query($sql,$con);
echo "<script>window.location = 'http://www.christophablake.com/test.php'</script>";
}

else
{
//Redirects user to comments page after successful insertion
echo "<script>window.location = 'http://www.christophablake.com/test.php'</script>";
echo "<script>show_alert()</script>";
}
//Close connection to database
mysql_close($con)
?>